package com.heima.media.controller;

import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.ChannelDto;
import com.heima.media.entity.WmChannel;
import com.heima.media.service.IWmChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
@Api(tags = "频道管理API") //Swagger注解
public class WmChannelController {
    @Autowired
    private IWmChannelService wmChannelService;
    //根据频道名查询
    @PostMapping("/list")
    @ApiOperation(value = "根据名称模糊查询分页列表",notes = "author:syl")//va是指的名称 no 是备注
    @ApiModelProperty(name = "dto",value = "查询对象",required = true,dataType = "ChannelDto")
    public ResponseResult listByName(@RequestBody ChannelDto dto){
    return wmChannelService.listByName(dto);
    }
    //保存频道
    @PostMapping()
    @ApiOperation(value = "saveWmChannel" ,notes = "保存频道")
    @ApiModelProperty(name ="wmChannel" ,dataType = "WmChannel" ,required = true)
    public ResponseResult saveWmChannel(@RequestBody WmChannel wmChannel){
        return wmChannelService.saveWmChannel(wmChannel);
    }
    //频道列表展示
    @GetMapping("/channels")
    @ApiOperation(value = "channels" ,notes = "频道列表展示")
    public ResponseResult channel(){
        List<WmChannel> list = wmChannelService.list();
        return ResponseResult.okResult(list);
    }
}
